commonlibsse_ng\re\b/BSCoreTypes.rs
1macro_rules! define_transparent_type {
2 ($(#[$id_docs:meta])* $name:ident($type:ty) $(#[$new_docs:meta])*, $(#[$get_docs:meta])*) => {
3 $(#[$id_docs])*
4 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
5 #[repr(transparent)]
6 pub struct $name($type);
7
8 impl $name {
9 $(#[$new_docs])*
10 #[inline]
11 pub const fn new(value: $type) -> Self {
12 Self(value)
13 }
14
15 $(#[$get_docs])*
16 #[inline]
17 pub const fn get(self) -> $type {
18 self.0
19 }
20 }
21 };
22}
23
24define_transparent_type!(
25 /// A transparent wrapper for `FormID` (equivalent to `std::uint32_t` in C++).
26 FormID(u32)
27 /// Creates a new `FormID` from a `u32` value.
28 ///
29 /// # Examples
30 /// ```
31 /// # use commonlibsse_ng::re::BSCoreTypes::FormID;
32 /// let form_id = FormID::new(12345);
33 /// ```
34,
35 /// Returns the contained value as a primitive type.
36 ///
37 /// # Examples
38 /// ```
39 /// # use commonlibsse_ng::re::BSCoreTypes::FormID;
40 /// let form_id = FormID::new(12345);
41 /// assert_eq!(form_id.get(), 12345);
42 /// ```
43);
44
45define_transparent_type!(
46 /// A transparent wrapper for `RefHandle` (equivalent to `std::uint32_t` in C++).
47 RefHandle(u32)
48 /// Creates a new `RefHandle` from a `u32` value.
49 ///
50 /// # Examples
51 /// ```
52 /// # use commonlibsse_ng::re::BSCoreTypes::RefHandle;
53 /// let ref_handle = RefHandle::new(98765);
54 /// ```
55,
56 /// Returns the contained value as a `u32` type.
57 ///
58 /// # Examples
59 /// ```
60 /// # use commonlibsse_ng::re::BSCoreTypes::RefHandle;
61 /// let ref_handle = RefHandle::new(98765);
62 /// assert_eq!(ref_handle.get(), 98765);
63 /// ```
64);
65
66define_transparent_type!(
67 /// A transparent wrapper for `VMHandle` (equivalent to `std::uint64_t` in C++).
68 VMHandle(u64)
69 /// Creates a new `VMHandle` from a `u64` value.
70 ///
71 /// # Examples
72 /// ```
73 /// # use commonlibsse_ng::re::BSCoreTypes::VMHandle;
74 /// let vm_handle = VMHandle::new(1234567890123456);
75 /// ```
76,
77 /// Returns the contained value as a `u64` type.
78 ///
79 /// # Examples
80 /// ```
81 /// # use commonlibsse_ng::re::BSCoreTypes::VMHandle;
82 /// let vm_handle = VMHandle::new(1234567890123456);
83 /// assert_eq!(vm_handle.get(), 1234567890123456);
84 /// ```
85);
86
87define_transparent_type!(
88 /// A transparent wrapper for `VMStackID` (equivalent to `std::uint32_t` in C++).
89 VMStackID(u32)
90 /// Creates a new `RefHandle` from a `u32` value.
91 ///
92 /// # Examples
93 /// ```
94 /// # use commonlibsse_ng::re::BSCoreTypes::VMStackID;
95 /// let ref_handle = VMStackID::new(1234);
96 /// ```
97,
98 /// Returns the contained value as a `u32` type.
99 ///
100 /// # Examples
101 /// ```
102 /// # use commonlibsse_ng::re::BSCoreTypes::VMStackID;
103 /// let vm_stack_id = VMStackID::new(1234);
104 /// assert_eq!(vm_stack_id.get(), 1234);
105 /// ```
106);
107
108define_transparent_type!(
109 /// A transparent wrapper for `VMTypeID` (equivalent to `std::uint32_t` in C++).
110 VMTypeID(u32)
111 /// Creates a new `VMTypeID` from a `u32` value.
112 ///
113 /// # Examples
114 /// ```
115 /// # use commonlibsse_ng::re::BSCoreTypes::VMTypeID;
116 /// let vm_type_id = VMTypeID::new(5678);
117 /// ```
118,
119 /// Returns the contained value as a `u32` type.
120 ///
121 /// # Examples
122 /// ```
123 /// # use commonlibsse_ng::re::BSCoreTypes::VMTypeID;
124 /// let vm_type_id = VMTypeID::new(5678);
125 /// assert_eq!(vm_type_id.get(), 5678);
126 /// ```
127);